package br.com.educa.log;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import br.com.educa.componentes.controller.ComponentsController;
import br.com.educa.modelo.security.Usuario;


privileged aspect MetodosLog {
    
	public Usuario ComponentsController.obterUsuario() {
		Usuario currentUser = null;
		try{
			currentUser  = (Usuario) (SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		}catch(Exception e){}
        return currentUser;
	}

	public String ComponentsController.obterIP() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		return request.getRemoteHost();
	}

	public String ComponentsController.obterPorta() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		return request.getRemotePort()+"";
	}
    
}
